<template>
  <div>
    <h3>学术论文著作</h3>
    <div class="table-body">
      <vxe-toolbar style="height: 100px;">
        <template #buttons>
          <el-row style="margin-bottom: 20px;">
            <el-col :span="7">
              <el-select v-model="searchForm.empTypeId" size="small" multiple collapse-tags
                filterable clearable placeholder="选择工作类型">
                <el-option :label="item" :value="key" v-for="(item,key,index) in dict_empType" :key="index"></el-option>
              </el-select>
              <el-button type="success" size="small" @click="searchForm.empTypeId = Object.keys(dict_empType)">全选
              </el-button>
            </el-col>
            <el-col :span="5">
              <el-input v-model="searchForm.name" size="small" style="width: 60%;" placeholder="论文题目"></el-input>
            </el-col>
            <el-col :span="12">
              <sportChangesportItem ref="sport2sportItem" search="search" :isEmp="true"
                :sportChangesportItemData="sportChangesportItemData" @selectDataChange='searchSelectDataChange' />
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="7" style="display: flex;">
              <el-button type="success" icon="el-icon-plus" size="medium" @click="insertEvent">新增</el-button>
              <el-button type="success" icon="el-icon-printer" size="medium" @click="exportData">导出</el-button>
              <el-button type="success" icon="el-icon-printer" size="medium" @click="printEvent">打印</el-button>
            </el-col>
            <el-col :span="9">
              <el-date-picker size="small" v-model="doubleDate" type="daterange" align="right" unlink-panels
                range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
              </el-date-picker>
            </el-col>
            <el-col :span="5">
              <el-button type="success" size="small" icon="el-icon-s-promotion" @click="searchSubmit"
                style="margin: 0 10px;">
                搜索</el-button>
              <vxe-button @click="clearTableFilter" status="warning" icon="el-icon-refresh-right"> 清空</vxe-button>
            </el-col>
            <el-col :span="3">
              <vxe-input style="float: right;" v-model.trim.lazy="filterName" type="search" placeholder="快捷检索"
                @input="searchEvent"></vxe-input>
            </el-col>
          </el-row>
        </template>
      </vxe-toolbar>
      <vxe-table resizable ref="XTable" show-overflow border max-height="800" stripe highlight-hover-row highlight-current-row
        :loading="loading" :data="dataList" @sort-change="sortChange">
        <vxe-table-column field="emp" title="教职员" sortable></vxe-table-column>
        <vxe-table-column field="empId2Type" title="专职" sortable></vxe-table-column>
        <vxe-table-column field="jempId2Type" title="兼职" sortable></vxe-table-column>
        <vxe-table-column field="name" title="论文题目" sortable></vxe-table-column>
        <vxe-table-column field="publishDate" title="发表时间" sortable></vxe-table-column>
        <vxe-table-column field="periodicalName" title="发表刊物" sortable></vxe-table-column>
        <vxe-table-column field="result" title="成绩" sortable></vxe-table-column>
        <vxe-table-column field="issn" title="国际标准期刊编号" sortable></vxe-table-column>
        <vxe-table-column field="writerRank" title="第几作者" sortable></vxe-table-column>
        <vxe-table-column field="total" title="总人数" sortable></vxe-table-column>
        <vxe-table-column field="publishType" title="发行类型" sortable></vxe-table-column>
        <vxe-table-column field="code" title="邮发代码" sortable></vxe-table-column>
        <vxe-table-column field="isOnNetName" title="网上可查" sortable></vxe-table-column>
        <vxe-table-column field="useCase" title="录用情况" sortable></vxe-table-column>
        <vxe-table-column field="subjectLevel" title="课题级别" sortable></vxe-table-column>
        <vxe-table-column field="rank" title="名次" sortable></vxe-table-column>
        <vxe-table-column field="wordCount" title="字数" sortable></vxe-table-column>
        <vxe-table-column field="" title="操作" width="110">
          <template #default="{ row,rowIndex }">
            <el-button @click="editEvent(row,rowIndex)" type="success" size="medium" icon="el-icon-edit" circle></el-button>
            <el-button @click="deleteEvent(row)" type="danger" size="medium" icon="el-icon-delete" circle></el-button>
          </template>
        </vxe-table-column>
        <vxe-table-column field="createUser" title="录入人" sortable></vxe-table-column>
        <vxe-table-column field="checkUser" title="审核人" sortable>
          <template #default="{ row }">
            <span v-if="row.checkUserId!=0">{{row.checkUser}}</span>
            <el-link v-else @click="checkedEvent(row)" type="success">{{row.checkUser}}</el-link>
          </template>
        </vxe-table-column>
      </vxe-table>
      <vxe-pager :loading="loading" :current-page="page.currentPage" :page-size="page.pageSize" :total="page.totalResult"
        :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']" @page-change="handlePageChange">
      </vxe-pager>
    </div>
    <vxe-modal v-model="insertModal" title="学术论文著作" height="80%" width="500">
      <template #default>
        <el-form inline-message ref="insertForm" :rules="rules" :model="insertForm" label-width="130px">
          <el-form-item label="运动项目" prop="sportId">
            <el-select v-model="insertForm.sportId" filterable clearable style="width: 100%;" placeholder="请选择" @change="sportChange">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_sport" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="运动小项" prop="sportItemId">
            <el-select v-model="insertForm.sportItemId" filterable clearable style="width: 100%;" placeholder="请选择" @change="sportItemChange">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_sportItem" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="教职员" prop="empId">
            <el-select v-model="insertForm.empId" filterable clearable style="width: 100%;" placeholder="请选择">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_emp" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="论文题目" prop="name">
            <el-input v-model="insertForm.name"></el-input>
          </el-form-item>
          <el-form-item label="发表时间" prop="publishDate">
            <el-date-picker type="date" placeholder="选择日期" v-model="insertForm.publishDate" style="width: 100%;">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="发表刊物" prop="periodical">
            <el-radio v-model="insertForm.periodical" label="1">发表刊物</el-radio>
            <el-radio v-model="insertForm.periodical" label="2">其他</el-radio>
          </el-form-item>
          <el-form-item label="成绩" prop="result">
            <el-input v-model="insertForm.result"></el-input>
          </el-form-item>
          <el-form-item label="国际标准期刊编号" prop="issn" label-width="130px">
            <el-input v-model="insertForm.issn"></el-input>
          </el-form-item>
          <el-form-item label="第几作者" prop="writerRank">
            <el-radio v-model="insertForm.writerRank" label="1"></el-radio>
            <el-radio v-model="insertForm.writerRank" label="2"></el-radio>
            <el-radio v-model="insertForm.writerRank" label="3"></el-radio>
            <el-radio v-model="insertForm.writerRank" label="4"></el-radio>
            <el-radio v-model="insertForm.writerRank" label="5"></el-radio>
          </el-form-item>
          <el-form-item label="总人数" prop="total">
            <el-input v-model="insertForm.total" type="number"></el-input>
          </el-form-item>
          <el-form-item label="发行类型" prop="publishTypeId">
            <el-radio v-model="insertForm.publishTypeId" v-for="(item,key,index) in dict_publishType" :label="key">{{item}}</el-radio>
          </el-form-item>
          <el-form-item label="邮发代码" prop="code">
            <el-input v-model="insertForm.code"></el-input>
          </el-form-item>
          <el-form-item label="网上可查" prop="isOnNet">
            <el-select v-model="insertForm.isOnNet" filterable clearable style="width: 100%;" placeholder="请选择">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_isOnNet" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="录用情况" prop="useCaseId">
            <el-select v-model="insertForm.useCaseId" filterable clearable style="width: 100%;" placeholder="请选择">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_useCase" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="课题级别" prop="subjectLevelId">
            <el-radio v-model="insertForm.subjectLevelId" v-for="(item,key,index) in dict_subjectLevel" :label="key">{{item}}</el-radio>
          </el-form-item>
          <el-form-item label="名次" prop="rankId">
            <el-select v-model="insertForm.rankId" filterable clearable style="width: 100%;" placeholder="请选择">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_rank" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="字数" prop="wordCountId">
            <el-radio v-model="insertForm.wordCountId" v-for="(item,key,index) in dict_wordCount" :label="key">{{item}}</el-radio>
          </el-form-item>
          <el-form-item>
            <el-button type="warning" size="small" @click="insertModal = false">取消</el-button>
            <el-button type="success" size="small" icon="el-icon-s-promotion" @click="insertSave">保存</el-button>
          </el-form-item>
        </el-form>
      </template>
    </vxe-modal>
  </div>
</template>
<script>
  import {
    paper_select,
    paper_insertByEmpId,
    paper_updateByEmpId,
    paper_deleteByEmpId,
    paper_check,
    currentRoleEmployee,
    sport_item_by_sportId
  } from '@/api/person.js'
  import {
    sport_by_org,
    pId2sportIds4emp1,
    genEmpType,
    employee_type,
    userId2EmpName,
    sport_item,
  } from '@/api/dict.js'
  import sportChangesportItem from '@/components/sport2sportItem/sport2sportItem.vue'
  export default {
    components: {
      sportChangesportItem
    },
    data() {
      return {
        doubleDate: '',
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        defaultDataList: [],
        dataList: [],
        page: {
          currentPage: 1,
          pageSize: 10,
          totalResult: 0
        },
        loading: false,
        filterName: '',
        insertModal: false,
        dict_empId2Type: {},
        dict_jempId2Type: {},
        dict_pId2TypeId: {},
        dict_jpId2TypeId: {},
        dict_empType: {},
        dict_userId2empName: {},
        dict_emp: {},
        dict_createUser: {},
        dict_checkUser: {},
        dict_publishType: {
          1: "公开发行",
        },
        dict_useCase: {
          1: "二级及以上学术论文报告会录用论文",
          2: "参加厅局级以上课题或研究项目",
          3: "公开出版的学术著作或教材",
        },
        dict_subjectLevel: {
          1: "省部级",
          2: "厅局级",
        },
        dict_rank: {
          1: "第一名",
          2: "第二名",
          3: "第三名",
          4: "第四名",
          5: "第五名",
        },
        dict_wordCount: {
          1: "两万字及以上",
          2: "少于两万字",
        },
        dict_periodical: {
          1: '发表刊物',
          2: '其他'
        },
        dict_writerRank: {
          1: '1',
          2: '2',
          3: '3',
          4: '4',
          5: '5',
        },
        dict_isOnNet: {
          1: "是",
          2: "否",
          3: "不详",
        },
        insertForm: {
          empId: '',
          sportId: '',
          sportItemId: '',
          name: '',
          publishDate: '',
          periodical: '',
          result: '',
          issn: '',
          writerRank: '',
          total: '',
          publishTypeId: '',
          code: '',
          isOnNet: '',
          useCaseId: '',
          subjectLevelId: '',
          rankId: '',
          wordCountId: '',
        },
        searchForm: {
          empTypeId: '',
          empId: '',
          sportId: '',
          sportItemId: '',
          name: '',
        },
        sportItemData: [],
        rules: {
          name: [{
            required: true,
            message: '这是必填项',
            trigger: 'blur'
          }, ],
          publishDate: [{
            required: true,
            message: '这是必填项',
            trigger: 'blur'
          }, ],
        },
        isInsert: true,
        paperId: '',
        pid: '',
        empData: {},
        sportChangesportItemData: {},
        dict_sport: {},
        dict_sportItem: {},
        search: false,
        currentIndex: null,
      }
    },
    created() {
      this.init_dict().then(()=>{
        this.paper_select()
      })
    },
    computed: {
      openDateValid() {
        if (this.insertForm.openDate && this.insertForm.closeDate) {
          if (this.insertForm.openDate > this.insertForm.closeDate) {
            this.$message.error('开始时间必须小于结束时间！')
            return false
          } else {
            return true
          }
        } else {
          return true
        }
      }
    },
    watch: {
      filterName(val) {
        if(!val){
          this.page = {
          currentPage: 1,
          pageSize: 10,
          totalResult: 0,
          }
          this.search = false
          this.findList()
        }
      }
    },
    methods: {
      searchSelectDataChange({
        sportId,
        sportItemId,
        person
      }) {
        this.searchForm.sportId = sportId
        this.searchForm.sportItemId = sportItemId
        this.searchForm.empId = person
      },
      insertSelectDataChange({
        sportId,
        sportItemId,
        person
      }) {
        this.insertForm.sportId = sportId
        this.insertForm.sportItemId = sportItemId
        this.insertForm.empId = person
      },
      clearTableFilter() {
        this.searchForm = {
          empTypeId: '',
          empId: '',
          sportId: '',
          sportItemId: '',
          name: '',
        }
        this.doubleDate = ''
        this.sportChangesportItemData = {}
        this.paper_select()
      },
      searchSubmit() {
        let data = {}
        if (this.searchForm.empTypeId) data.empTypeIdStr = this.searchForm.empTypeId.join(',')
        if (this.searchForm.empId) data.empId = this.searchForm.empId
        if (this.searchForm.sportId) data.sportId = this.searchForm.sportId
        if (this.searchForm.sportItemId) data.sportItemId = this.searchForm.sportItemId
        if (this.searchForm.name) data.name = this.searchForm.name
        if (this.doubleDate){
          data.beginDateT = this.$moment(this.doubleDate[0]).format('YYYY-MM-DD') + ' 00:00:00'
          data.endDateT = this.$moment(this.doubleDate[1]).format('YYYY-MM-DD') + ' 00:00:00'
        }
        paper_select(data).then(res => {
          if (res.code === 200 && res.data.length != 0) {
            this.page = {
              currentPage: 1,
              pageSize: 10,
              totalResult: 0
            }
            this.init_data(res.data)
          } else {
            this.defaultDataList = []
          }
        }).then(() => {
          this.findList()
        })
      },
      deleteEvent(row) {
        this.$confirm('此操作将永久删除该条记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          paper_deleteByEmpId({
            paperId: row.paperId,
            empId: row.empId
          }).then(res => {
            if (res.code === 200) {
              this.defaultDataList.forEach((item,index)=>{
              	if(item.paperId == row.paperId){
              	  this.defaultDataList.splice(index,1)
              	}
              })
              this.init_data(this.defaultDataList)
              this.findList()
              this.$message.success('删除成功！')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      checkedEvent(row) {
        this.$confirm('注意：审核过之后，该条数据将不能再被修改', '审核', {
          confirmButtonText: '√通过审核',
          cancelButtonText: '放弃审核',
          type: 'warning'
        }).then(() => {
          paper_check({
            paperId: row.paperId
          }).then(res => {
            if (res.code === 200) {
              this.paper_select()
              this.$message.success('已审核.！')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消审核.'
          });
        });
      },
      editEvent(row,rowIndex) {
        this.currentIndex = rowIndex
        if (row.checkUserId!=0) {
          this.$message.warning('已经审核过的数据不能修改')
        } else {
          this.insertForm.sportId = ''
          this.insertForm.sportItemId = ''
          this.sportChange()
          this.paperId = row.paperId
          this.insertForm.empId = row.empId+''
          this.insertForm.name = row.name
          this.insertForm.publishDate = row.publishDate
          this.insertForm.periodical = row.periodical
          this.insertForm.result = row.result
          this.insertForm.issn = row.issn
          this.insertForm.writerRank = row.writerRank
          this.insertForm.total = row.total
          this.insertForm.publishTypeId = row.publishTypeId==0?'':row.publishTypeId+''
          this.insertForm.code = row.code
          this.insertForm.isOnNet = row.isOnNet==0?'':row.isOnNet+''
          this.insertForm.useCaseId = row.useCaseId==0?'':row.useCaseId+''
          this.insertForm.subjectLevelId = row.subjectLevelId==0?'':row.subjectLevelId+''
          this.insertForm.rankId = row.rankId==0?'':row.rankId+''
          this.insertForm.wordCountId = row.wordCountId==0?'':row.wordCountId+''
          this.isInsert = false
          this.insertModal = true
        }
      },
      insertSave() {
        this.$refs.insertForm.validate((valid) => {
          if (valid && this.openDateValid ) {
            let data = {}
            if (this.insertForm.empId) data.empId = this.insertForm.empId
            if (this.insertForm.empId2TypeId) data.empId2TypeId = this.insertForm.empId2TypeId
            if (this.insertForm.name) data.name = this.insertForm.name
            if (this.insertForm.publishDate) data.publishDate = this.$moment(this.insertForm.publishDate).format(
              'YYYY-MM-DD') + ' 00:00:00'
            if (this.insertForm.periodical) data.periodical = this.insertForm.periodical
            if (this.insertForm.result) data.result = this.insertForm.result
            if (this.insertForm.issn) data.issn = this.insertForm.issn
            if (this.insertForm.writerRank) data.writerRank = this.insertForm.writerRank
            if (this.insertForm.total) data.total = this.insertForm.total
            if (this.insertForm.publishTypeId) data.publishTypeId = this.insertForm.publishTypeId
            if (this.insertForm.code) data.code = this.insertForm.code
            if (this.insertForm.isOnNet) data.isOnNet = this.insertForm.isOnNet
            if (this.insertForm.useCaseId) data.useCaseId = this.insertForm.useCaseId
            if (this.insertForm.subjectLevelId) data.subjectLevelId = this.insertForm.subjectLevelId
            if (this.insertForm.rankId) data.rankId = this.insertForm.rankId
            if (this.insertForm.wordCountId) data.wordCountId = this.insertForm.wordCountId
            if (this.isInsert) {
              paper_insertByEmpId(data).then(res => {
                if (res.code === 200) {
                  this.dataList.unshift(res.data)
                  this.defaultDataList.push(res.data)
                  this.init_data(this.defaultDataList)
                  this.page.totalResult+=1
                  this.$refs.XTable.setCurrentRow(this.dataList[0])
                  this.$message.success('保存成功')
                  this.insertSuccess = true
                  this.insertModal = false
                } else {
                  this.$message.error(res.message)
                }
              })
            } else {
              data.paperId = this.paperId
              paper_updateByEmpId(data).then(res => {
                if (res.code === 200) {
                  Object.assign(this.dataList[this.currentIndex],res.data)
                  this.defaultDataList.forEach(item=>{
                  	if(res.data.paperId==item.paperId){
                  	  Object.assign(item,res.data)
                  	}
                  })
                  this.init_data(this.defaultDataList)
                  this.$message.success('修改成功')
                  this.insertModal = false
                } else {
                  this.$message.error(res.message)
                }
              })
            }
          } else {
            return false;
          }
        })
      },
      insertEvent() {
        this.insertForm = {
          empId: '',
          sportId: '',
          sportItemId: '',
          name: '',
          publishDate: '',
          periodical: '',
          result: '',
          issn: '',
          writerRank: '',
          total: '',
          publishTypeId: '',
          code: '',
          isOnNet: '',
          useCaseId: '',
          subjectLevelId: '',
          rankId: '',
          wordCountId: '',
        }
        this.sportChangesportItemData = {}
        this.isInsert = true
        this.insertModal = true
      },
      sportItemChange(e) {
        this.insertForm.empId = ''
        this.dict_emp = {}
        let data = {}
        if (this.insertForm.sportId || this.searchForm.sportId) data.sportId = this.insertForm.sportId || this
          .searchForm.sportId
        if (this.insertForm.sportItemId || this.searchForm.sportItemId) data.sportItemId = this.insertForm
          .sportItemId || this.searchForm.sportItemId
        currentRoleEmployee(data).then(res2 => {
          this.empData.forEach(item=>{
            this.dict_emp[item.empId] = item.name
          })
        })
      },
      sportChange(e) {
        this.insertForm.sportItemId = ''
        this.insertForm.empId = ''
        this.searchForm.sportItemId = ''
        this.searchForm.empId = ''
        sport_item_by_sportId({
          sportId: e || this.insertForm.sportId || this.searchForm.sportId
        }).then(res => {
          if (res.code === 200) {
            this.sportItemData = res.data
            let dict = {}
            if(this.sportItemData.length!=0){
              this.sportItemData.forEach(item=>{
                dict[item.sportItemId] = item.name
              })
            }
            this.dict_sportItem = dict
            let data = {}
            if (this.insertForm.sportId || this.searchForm.sportId) data.sportId = this.insertForm.sportId || this
              .searchForm.sportId
            if (this.insertForm.sportItemId || this.searchForm.sportItemId) data.sportItemId = this.insertForm
              .sportItemId || this.searchForm.sportItemId
            currentRoleEmployee(data).then(res2 => {
              this.empData = res2.data
              let dict2 = {}
              this.empData.forEach(item=>{
                dict2[item.empId] = item.name
              })
              this.dict_emp = dict2
            })
          }
        })
      },
      exportData() {
        this.$refs.XTable.exportData({
          filename: this.$store.state.user.org+'教职员'+this.$route.meta.title, type: 'csv',
          data: this.search?this.dataList:this.defaultDataList
        })
      },
      printEvent() {
        let topHtml = '<h2>学术论文著作</h2>'
        this.searchEvent()
        setTimeout(() => {
          this.$refs.XTable.print({
            sheetName: '学术论文著作',
            beforePrintMethod: ({
              content
            }) => {
              return topHtml + content
            }
          })
        }, 1000)
      },
      searchEvent() {
        const filterName = this.$XEUtils.toValueString(this.filterName).trim().toLowerCase()
        if (filterName) {
          const filterRE = filterName
          const searchProps = this.searchProps
          const rest = this.defaultDataList.filter(item => searchProps.some(key => this.$XEUtils.toValueString(item[
            key]).toLowerCase().indexOf(filterName) > -1))
          this.dataList = rest.map(row => {
            const item = Object.assign({}, row)
            searchProps.forEach(key => {
              item[key] = this.$XEUtils.toValueString(item[key]).replace(filterRE, match => match)
            })
            return item
          })
          this.page = {
            currentPage: 1,
            pageSize: this.dataList.length,
            totalResult: this.dataList.length
          }
          this.search = true
        } else {
          this.dataList = this.defaultDataList
     }
      },
      paper_select() {
        paper_select().then(res => {
          if (res.code === 200 && res.data.length != 0) {
            this.init_data(res.data)
          } else {
            this.defaultDataList = []
          }
        }).then(() => {
          this.findList()
        })
      },
      init_data(data) {
        if(data.length==0) return
        data.forEach(item => {
          item.empId2Type = this.dict_empId2TypeId[item.empId]
          item.jempId2Type = this.dict_jempId2TypeId[item.empId]
          item.emp = this.dict_emp[item.empId]
          item.periodicalName = this.dict_periodical[item.periodical]
          item.publishDate = this.$moment(item.publishDate).format('YYYY-MM-DD') == 'Invalid date' ? '' : this
            .$moment(item.publishDate).format('YYYY-MM-DD')
          item.publishType = this.dict_publishType[item.publishTypeId]
          item.writerRank = this.dict_writerRank[item.writerRank]
          item.isOnNetName = this.dict_isOnNet[item.isOnNet]
          item.useCase = this.dict_useCase[item.useCaseId]
          item.subjectLevel = this.dict_subjectLevel[item.subjectLevelId]
          item.rank = this.dict_rank[item.rankId]
          item.total = item.total==0?'':item.total
          item.wordCount = this.dict_wordCount[item.wordCountId]
          item.createUser = this.dict_userId2empName[item.createUserId]
          if (item.checkUserId) {
            item.checkUser = this.dict_userId2empName[item.checkUserId]
          } else {
            item.checkUser = '未审核'
          }
        })
        this.searchProps = Object.keys(data[0])
        this.defaultDataList = data
      },
      init_dict() {
        return new Promise((resolve, reject) => {
          userId2EmpName().then(res => {
            this.dict_userId2empName = res
          })
          sport_by_org().then(res=>{
            this.dict_sport = res
          })
          genEmpType(true).then(res => {
            var dict_jempId2TypeId = {}
            var dict_empId2TypeId = {}
            var dict_pId2TypeId = {}
            var dict_jpId2TypeId = {}
            var dict_empType = {
              1: '教练员',
              2: '文化教师',
              3: '科医人员',
              4: '行政管理',
            }
            var employees = res.data;
            for (var i = 0; i < employees.length; i++) {
              var jempTypeName = '';
              if (employees[i].height.length > 0) {
                var ids = employees[i].height.split(',');
                for (var j = 0; j < ids.length; j++) {
                  jempTypeName += dict_empType[ids[j]] + ','
                }
                jempTypeName = jempTypeName.substring(0, jempTypeName.length - 1)
                dict_jempId2TypeId[employees[i].empId] = jempTypeName
                dict_jpId2TypeId[employees[i].pid] = jempTypeName
              } else {
                dict_jempId2TypeId[employees[i].empId] = ''
                dict_jpId2TypeId[employees[i].pid] = ''
              }
              if (employees[i].empTypeId) {
                dict_empId2TypeId[employees[i].empId] = dict_empType[employees[i].empTypeId]
                dict_pId2TypeId[employees[i].pid] = dict_empType[employees[i].empTypeId]
              } else {
                dict_empId2TypeId[employees[i].empId] = '';
                dict_pId2TypeId[employees[i].pid] = '';
              }
            }
            this.dict_empId2TypeId = dict_empId2TypeId
            this.dict_jempId2TypeId = dict_jempId2TypeId
            this.dict_pId2TypeId = dict_pId2TypeId
            this.dict_jpId2TypeId = dict_jpId2TypeId
            this.dict_empType = dict_empType
            resolve()
          })
          currentRoleEmployee().then(res => {
            let dict = {}
            this.empData = res.data
            res.data.forEach(item => {
              dict[item.empId] = item.name
            })
            this.dict_emp = dict
          })
        })
      },
      handlePageChange({
        currentPage,
        pageSize
      }) {
        this.page.currentPage = currentPage
        this.page.pageSize = pageSize
        this.findList()
      },
      sortChange() {
        if(!this.search){
          this.page.pageSize = this.defaultDataList.length
          this.findList()
        }else{
          this.page.pageSize = this.dataList.length
        }
      },
      findList() {
        this.loading = true
        setTimeout(() => {
          if(this.insertSuccess){
            this.page.totalResult = this.defaultDataList.length
            this.page.currentPage = Math.ceil(this.page.totalResult/this.page.pageSize)
            this.dataList = this.defaultDataList.slice((this.page.currentPage - 1) * this.page
              .pageSize, this.page.currentPage * this.page.pageSize)
            this.$refs.XTable.setCurrentRow(this.dataList[this.dataList.length-1])
            this.insertSuccess = false
          }else{
            this.page.totalResult = this.defaultDataList.length
            this.dataList = this.defaultDataList.slice((this.page.currentPage - 1) * this.page
              .pageSize, this.page.currentPage * this.page.pageSize)
          }
          this.loading = false
        }, 300)
      },
    }
  }
</script>

<style lang="scss" scoped>

</style>
